package com.css.fxfzaqbz.modules.assess2.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.assess2.entity.KeyplaceRiskassessment;
import com.css.fxfzaqbz.modules.assess2.entity.KrTask;
import com.css.fxfzaqbz.modules.assess2.service.KeyplaceRiskassessmentService;
import com.css.fxfzaqbz.modules.assess2.service.KrTaskService;
import com.css.fxfzaqbz.modules.data.entity.AidedAnalyse;
import com.css.fxfzaqbz.modules.data.vo.AidedAnalyseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 重点场所风险评估
 */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class KeyplaceRiskassessmentController {
    @Resource
    private KeyplaceRiskassessmentService keyplaceRiskassessmentService;

    /**
     * 逻辑删除
     * @param id
     * @return
     */
    @PostMapping("/delKeyplaceRiskassessment")
    public RestResponse deleteKeyplaceRiskassessment(String id) {
        RestResponse restResponse = null;
        try {
            keyplaceRiskassessmentService.deleteKeyplaceRiskassessment(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除重点场所风险评估失败!", e);
            restResponse = RestResponse.fail("删除重点场所风险评估失败!");
        }
        return restResponse;
    }

    /**
     * 修改
     *
     * @param keyplaceRiskassessment
     * @return
     */
    @PostMapping("/updateKeyplaceRiskassessment")
    public RestResponse<KeyplaceRiskassessment> updateKeyplaceRiskassessment(@RequestBody KeyplaceRiskassessment keyplaceRiskassessment) {
        RestResponse restResponse = null;
        try {
            keyplaceRiskassessmentService.updateKeyplaceRiskassessment(keyplaceRiskassessment);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("修改重点场所风险评估失败!", e);
            restResponse = RestResponse.fail("修改重点场所风险评估失败!");
        }
        return restResponse;
    }

    /**
     * 根据活动id全查询-过程稿
     *
     * @param id
     * @return
     */
    @GetMapping("/getKeyplaceRiskassessmentByActiveId/{id}")
    public RestResponse getByIaId(@PathVariable("id") String id) {

        RestResponse restResponse = null;
        try {
            List<KeyplaceRiskassessment> keyplaceRiskassessments = keyplaceRiskassessmentService.getByIaId(id);
            restResponse = RestResponse.succeed(keyplaceRiskassessments);
        } catch (Exception e) {
            log.error("查询重点场所风险评估失败!", e);
            restResponse = RestResponse.fail("查询重点场所风险评估失败");
        }
        return restResponse;
    }

    /**
     * 根据活动id全查询-最终成果
     *
     * @param id
     * @return
     */
    @GetMapping("/getKeyplaceRiskassessmentByIaId/{id}")
    public RestResponse getKeyplaceRiskassessmentByIaId(@PathVariable("id") String id) {

        RestResponse restResponse = null;
        try {
            List<KeyplaceRiskassessment> keyplaceRiskassessments = keyplaceRiskassessmentService.getKeyplaceRiskassessmentByIaId(id);
            restResponse = RestResponse.succeed(keyplaceRiskassessments);
        } catch (Exception e) {
            log.error("查询重点场所风险评估失败!", e);
            restResponse = RestResponse.fail("查询重点场所风险评估失败");
        }
        return restResponse;
    }

    /**
     * 根据id查询数据
     * @param id
     * @return
     */
    @GetMapping("/getKeyplaceRiskassessmentById")
    public RestResponse getKeyplaceRiskassessmentById(String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(keyplaceRiskassessmentService.getKeyplaceRiskassessmentById(id));
        } catch (Exception e) {
            log.error("获取重点场所风险评估失败!", e);
            restResponse = RestResponse.fail("获取重点场所风险评估失败!");
        }
        return restResponse;
    }

    /**
     * 新增
     *
     * @param keyplaceRiskassessment
     * @return
     */
    @PostMapping("/saveKeyplaceRiskassessment")
    public RestResponse saveKeyplaceRiskassessment(@RequestBody KeyplaceRiskassessment keyplaceRiskassessment) {
        RestResponse restResponse = null;
        try {
            keyplaceRiskassessmentService.savekeyplaceRiskassessment(keyplaceRiskassessment);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("新增重点场所风险评估失败", e);
            restResponse = RestResponse.fail("新增重点场所风险评估失败!");
        }
        return restResponse;
    }

    /**
     * 重复校验
     * @param keyplaceRiskassessment
     * @return
     */
    @PostMapping("/checkKeyplaceRiskassessment")
    public RestResponse check(@RequestBody KeyplaceRiskassessment keyplaceRiskassessment){
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(keyplaceRiskassessmentService.check(keyplaceRiskassessment));
        } catch (Exception e) {
            log.error("添加描述失败!", e);
            restResponse = RestResponse.fail("添加描述失败!");
        }
        return restResponse;
    }

    /**
     * 提交最终成果
     * @param id
     * @return
     */
    @PostMapping("/submitResultKeyplaceRiskassessment")
    public RestResponse submitResult(String id){
        RestResponse restResponse = null;
        try {
            keyplaceRiskassessmentService.submitResult(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("提交最终成果失败!", e);
            restResponse = RestResponse.fail("提交最终成果失败!");
        }
        return restResponse;
    }

    /**
     * 添加描述
     * @param aidedAnalyseVo
     * @return
     */
    @PostMapping("/saveDescriptionKeyplaceRiskassessment")
    public RestResponse saveDescription(@RequestBody AidedAnalyseVo aidedAnalyseVo) {
        RestResponse restResponse = null;
        try {
            keyplaceRiskassessmentService.saveDescription(aidedAnalyseVo);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("添加描述失败!", e);
            restResponse = RestResponse.fail("添加描述失败!");
        }
        return restResponse;
    }
    /**
     * 移除最终成果
     * @param id
     * @return
     */
    @PostMapping("/removeResultKeyplaceRiskassessment")
    public RestResponse removeResult(String id){
        RestResponse restResponse = null;
        try {
            keyplaceRiskassessmentService.removeResult(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("移除最终成果失败!", e);
            restResponse = RestResponse.fail("移除最终成果失败!");
        }
        return restResponse;
    }

    /**
     * 最终提交
     * @param ids
     * @return
     */
    @PostMapping("/finalSubmissionKeyplaceRiskassessment/{ids}")
    public RestResponse finalSubmission(@PathVariable("ids") List<String> ids){
        RestResponse restResponse = null;
        try {
            keyplaceRiskassessmentService.finalSubmission(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("最终提交失败!", e);
            restResponse = RestResponse.fail("最终提交失败!");
        }
        return restResponse;
    }
}
